//
//  AlerttypeView.m
//  BestFriend
//
//  Created by mac on 16/4/1.
//  Copyright © 2016年 menglingdong. All rights reserved.
//

#import "AlerttypeView.h"
#import "LewPopupViewAnimationSpring.h"
#import "LewPopupViewAnimationFade.h"
#import "UIViewController+LewPopupViewController.h"
//#import "MHNetManager.h"




@implementation AlerttypeView


- (id)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    self.backgroundColor=[UIColor clearColor];
    self.frame=CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    [self getUserInfo];

    self.dataArr=[[NSMutableArray alloc]init];
    _innerView = [[UIView alloc] initWithFrame:CGRectMake(50, SCREEN_HEIGHT - 400, SCREEN_WIDTH- 100, 300)];
    _innerView.backgroundColor = [UIColor whiteColor];
    _innerView.layer.cornerRadius = 5;
    [self addSubview:_innerView];

    _listArry=[[NSMutableArray alloc]init];
 [self getUI];
    return self;
   
}

- (void)getUI{
    _typetableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH - 100, 300) style:UITableViewStylePlain];
    _typetableView.dataSource = self;
    _typetableView.delegate = self;
    _typetableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    _typetableView.backgroundColor = [UIColor clearColor];
    [_innerView addSubview:_typetableView];
}

// 获取
-(void)getUserInfo{
    FXTHttpRequestModel * requestModel = [[FXTHttpRequestModel alloc] init];
    requestModel.type = FXTHttpType_POST;
    requestModel.appendUrl = @"/Task/worktype_list";
    requestModel.callback = ^(FXTHttpResponseModel * result, NSError *error){
        if (result.state ==FXTReponseCodeState_Success) {
//            NSLog(@"wwwwwwwwwwww%@",result.data);
            _listArry=result.data;
            for ( NSDictionary* dic in _listArry) {
                [self .dataArr  addObject:[dic objectForKey:@"name"]];
            }
            [self getUI];
            [_typetableView reloadData];
        }else {
            [DisplayHelper displayWarningAlert:result.alertMsg];
        }
    };
    [[FXTHttpSessionManager sharedHttpSessionManager] sendHttpRequestParam:requestModel];
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 44;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

     return _listArry.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 44;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, 100, 44)];
    label.textColor = RGBCOLOR(40, 40, 40);
    label.font = [UIFont systemFontOfSize:16];
    label.text = @"选择";
    [view addSubview:label];
    
    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 43, SCREEN_WIDTH - 100, 1)];
    label1.backgroundColor = RGBCOLOR(233, 234, 235);
    [view addSubview:label1];
    
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
 


//    self.dataArr=[[NSMutableArray alloc]initWithObjects:@"可爱型",@"热辣型",@"青春时尚型",@"文静的",@"古典型",@"冷艳型",@"温柔型", @"贤惠 贤妻良母型",nil];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"TableViewCell"];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = [UIColor whiteColor];
    }
   cell.textLabel.text=self.dataArr[indexPath.row];
//    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0, 43, SCREEN_WIDTH - 100, 1)];
//    label1.backgroundColor = RGBCOLOR(233, 234, 235);
//    [cell.contentView addSubview:label1];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [_parentVC lew_dismissPopupViewWithanimation:[LewPopupViewAnimationFade new]];
    if ([_delegate respondsToSelector:@selector(showTyp:)]) {
        NSString *title = self.dataArr[indexPath.row];
        [_delegate showTyp:title];
        }
  
}

+ (instancetype)defaultTypeView{
    return [[AlerttypeView alloc]initWithFrame:CGRectMake(0, -60*kAppScale, SCREEN_WIDTH-50*kAppScale, 130*kAppScale)];
}

@end
